package com.central.apps.handler.MaterialInventory;

import cn.hutool.core.map.MapUtil;
import com.central.app.common.base.BaseHandler;
import com.central.app.service.HandlerService;
import com.central.apps.handler.base.LvBaseHandler;
import com.central.app.common.util.BLuntil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 库存管理
 */
@Component
public class InventorysHandler  extends LvBaseHandler {
    @Autowired
    private HandlerService handlerService;

    @Override
    public void afterSave(String app, String objName, Map<String, Object> data, boolean isUpdate) throws Exception {
        if("InventorysApp".equals(app)){
            /**
             * 库存调整 功能
             */
            if("bl_Inventorys".equals(objName)){
//                String location=data.get("LOCATION").toString();
//                String itemNUm=data.get("ITEMNUM").toString();
                //获取调整记录
                List<Map<String, Object>> list= BLuntil.getLineList(data,"TableUKey54030");
                //
                //将调整后数量  更新至库存表中
                if(list!=null && list.size()>0){
                    String num= BLuntil.getParameter(list.get(0),"NUMBER");
//                    String num=list.get(0).get("NUMBER").toString();//调整后数量
                    data.put("actqty",num);//库存余量
                    data.put("currentqty",num);//可用量
////                    data.put("CHANGEDATE",new Date());//调整时间
                    handlerService.update("bl_Inventorys",data);
                }
            }

        }
        super.afterSave(app, objName, data, isUpdate);
    }
}
